import request from "@/api/request";

/**
 * 获取系统参数配置分页列表
 * @param params
 * @returns
 */
export const getSysConfigPageList = (params: SysConfigPageParams) => {
  return new Promise<PageType<SysConfigType>>(async (resolve, reject) => {
    const res: AxiosResData<PageType<SysConfigType>> = await request.get(
      "/sysConfig/getListByPage",
      {
        params,
      }
    );
    resolve(res.data?.result || {});
  });
};
/**
 * 新增系统参数配置
 * @param data
 * @returns
 */
export const addSysConfig = (data: SysConfigParams) => {
  return new Promise<boolean>(async (resolve, reject) => {
    const res: AxiosResData<boolean> = await request.post(
      "/sysConfig/add",
      data
    );
    resolve(res.data?.result || false);
  });
};

/**
 * 修改系统参数配置
 * @param data
 * @returns
 */
export const updateSysConfig = (data: SysConfigParams) => {
  return new Promise<boolean>(async (resolve, reject) => {
    const res: AxiosResData<boolean> = await request.put(
      "/sysConfig/update",
      data
    );
    resolve(res.data?.result || false);
  });
};

/**
 * 删除系统参数配置
 * @param data
 * @returns
 */
export const deleteSysConfigById = (id: string) => {
  return new Promise<boolean>(async (resolve, reject) => {
    const res: AxiosResData<boolean> = await request.delete(
      `/sysConfig/deleteById/${id}`
    );
    resolve(res.data?.result || false);
  });
};

/**
 * 批量删除系统参数配置
 * @param data
 * @returns
 */
export const deleteSysConfigByIds = (data: string[]) => {
  return new Promise<boolean>(async (resolve, reject) => {
    const res: AxiosResData<boolean> = await request.delete(
      `/sysConfig/deleteById`,
      {
        data,
      }
    );
    resolve(res.data?.result || false);
  });
};
